<?php
class clsTrigger extends clsDao {
	protected function gTrigger($tabela, $insert = '', $update = '', $delete = '') {
		if (substr ( $insert, - 1 ) == ';')
			$insert = substr ( $insert, 0, - 1 );
		
		if (substr ( $update, - 1 ) == ';')
			$update = substr ( $update, 0, - 1 );
		
		if (substr ( $delete, - 1 ) == ';')
			$delete = substr ( $delete, 0, - 1 );
		
		$tgr = '';
		if ($insert != '') {
			$tgr .= "
DELIMITER $$
	DROP TRIGGER IF EXISTS " . $tabela . "Inser;
	CREATE TRIGGER " . $tabela . "Inser
	BEFORE INSERT ON $tabela
	FOR EACH ROW BEGIN
		$insert;
	END$$
DELIMITER $$";
		}
		
		if ($update != '') {
			$tgr .= "

DELIMITER $$
	DROP TRIGGER IF EXISTS " . $tabela . "Updt;
	CREATE TRIGGER " . $tabela . "Updt
	BEFORE UPDATE ON $tabela
	FOR EACH ROW BEGIN
		$update;
	END$$
DELIMITER $$";
		}
		
		if ($delete != '') {
			$tgr .= "
			
DELIMITER $$
	DROP TRIGGER IF EXISTS " . $tabela . "Dele;
	CREATE TRIGGER " . $tabela . "Dele
	BEFORE DELETE ON $tabela
	FOR EACH ROW BEGIN
		$delete;
	END$$
DELIMITER $$";
		}
		
		return $tgr."\n";
	}
}

?>